//
//  DKWCredApplyTableViewCell.m
//  CreditHub
//
//  Created by chenglang on 2024/9/28.
//

#import "DKWCredApplyTableViewCell.h"
#import "DKWCredApplyItemViewCell.h"

@implementation DKWCredApplyTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectIndex = -1;
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"DKWCredApplyItemViewCell" bundle:nil] forCellWithReuseIdentifier:@"DKWCredApplyItemViewCell"];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
}

- (void)setDicInfo:(NSDictionary *)dicInfo{
    _dicInfo = dicInfo;
    self.labelTitle.text = dicInfo[@"outside"];
    self.selectIndex = CHStringIsEmpty(dicInfo[@"index"])?-1:[dicInfo[@"index"] integerValue];
    NSArray *array = [NSArray arrayWithArray:self.dicInfo[@"select"]];
    self.layoutCoHeight.constant = 70*array.count;
    [self.collectionView reloadData];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    NSArray *array = [NSArray arrayWithArray:self.dicInfo[@"select"]];
    return array.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DKWCredApplyItemViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DKWCredApplyItemViewCell" forIndexPath:indexPath];
    NSArray *array = [NSArray arrayWithArray:self.dicInfo[@"select"]];
    cell.labelTitle.text = array[indexPath.row];
    if(self.selectIndex == indexPath.row){
        cell.viewContent.backgroundColor = colorWithHex(0xFBE307);
        cell.labelTitle.textColor = UIColor.blackColor;
        cell.imgViewSelect.hidden = NO;
    }else{
        cell.viewContent.backgroundColor = UIColor.whiteColor;
        cell.labelTitle.textColor = colorWithHex(0x7F8192);
        cell.imgViewSelect.hidden = YES;
    }
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    return CGSizeMake(SCREEN_WIDTH-30, 70);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    
    return 0;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    self.selectIndex = indexPath.row;
    [self.collectionView reloadData];
    if(self.selectBlock){
        self.selectBlock(indexPath.row);
    }
}

@end
